package com.syedu.day06.homework;

import cn.hutool.core.util.ArrayUtil;

/**
 * description：员工类
 * @author Administrator
 * @date 2022/3/15 16:07
 */
public class Employee {
    int id;//编号
    String name;//姓名
    double salary;//工资

    //二选一
    //方式一:
    //Employee manager;//上司,当前类的员工就是下属

    //方式二:
    Employee[] employees;//下属们,当前类的员工就是他们的上司

    public Employee() {
        
    }

    public Employee(int _id, String _name, double _salary) {
        id = _id;
        name = _name;
        salary = _salary;
    }

    public Employee(int _id, String _name, double _salary, Employee[] _employees) {
        id = _id;
        name = _name;
        salary = _salary;
        employees = _employees;
    }

    /**
     * 添加下属的方法
     */
    public void addEmp(Employee newEmployee){
        employees = ArrayUtil.append(employees,newEmployee);
    }

    /**
     * 输出自己所属下属的方法
     */
    public void showEmps() {
        if (employees != null && employees.length > 0) {
            for (Employee e : employees) {
                System.out.println(e.id + "," + e.name + "," + e.salary);
            }
        }
    }

    /**
     * 获取自己下属的人数个数
     */
    public int getEmpCount() {
        int count = 0;
        if (employees != null) {
            count = employees.length;
        }
        return count;
    }
}